package com.peycard.persistence.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import com.peycard.persistence.PersistenceException;
import com.peycard.persistence.dao.local.AdSysUserDAOLocal;
import com.peycard.persistence.entities.Adsysuser;

/**
 * Session Bean implementation class AsSysUserDAO
 */
@Stateless
public class AdSysUserDAO extends GenericDAOImpl<Adsysuser, Long> implements AdSysUserDAOLocal {

    /**
     * Default constructor. 
     */
    public AdSysUserDAO() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public Adsysuser findByName(String name) throws PersistenceException{
    	try{
    		Query query = getEntityManager().createNamedQuery("findAdsysuserByName");
			query.setParameter("name", name);    		
			Adsysuser user = (Adsysuser) query.getSingleResult();
			return user;
    	}catch(Exception e){    		
    		throw new PersistenceException("Error en xx:"+e.getMessage(), e);
    	}
    }
    
    @Override
    public Adsysuser findByEmail(String email) throws PersistenceException{
    	try{
    		Query query = getEntityManager().createNamedQuery("findAdsysuserByEmail");
			query.setParameter("email", email);
			Adsysuser user = (Adsysuser) query
			.getSingleResult();
			return user;
    	}catch(Exception e){
    		throw new PersistenceException("Error en xx:"+e.getMessage(), e);
    	}
    }
    
    public List<Adsysuser> getUsers() throws PersistenceException{
    	try{
    		Query query = getEntityManager().createNamedQuery("getUsers");			
			List<Adsysuser> users = (List<Adsysuser>) query.getResultList();
			return users;
    	}catch(Exception e){
    		throw new PersistenceException("Error en xx:"+e.getMessage(), e);
    	}
    }

}
